<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.BackOfficeModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    MvcCms -
    <%=ViewData["PageTitle"]%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <style type="text/css">
        label.error
        {
            float: none;
            color: red;
            padding-left: .5em;
            vertical-align: top;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="contentpage-outerdiv">
        <h2>
            <%=ViewData["PageTitle"]%></h2>
        <span class="field-validation-error">
            <%=ViewData["message"].ToString()%></span>
        <% using (Html.BeginForm("FileManager", "BackOffice", FormMethod.Post, new { id = "form1", enctype = "multipart/form-data" }))
           {%>
        <div>
            <fieldset>
                <legend>Import Files</legend>
                <div>
                    <table>
                        <tr>
                            <td>
                                Zip File:
                            </td>
                            <td>
                                <input type="file" id="filezip" name="filezip" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Single File:
                            </td>
                            <td>
                                <input type="file" id="singlefile" name="singlefile" />
                            </td>
                        </tr>
                    </table>
                    <br />
                    <span>
                        <input type="submit" id="btnImport" value="Import" /></span>
                </div>
            </fieldset>
        </div>
        <div>
            <fieldset>
                <legend>
                    <%=Html.Encode(Model._Files.Count().ToString())%>
                    Files Detected</legend>
                <table border="1">
                    <tr>
                        <th>
                            File Name
                        </th>
                        <th>
                            Size
                        </th>
                        <th>
                            File Date
                        </th>
                        <th>
                        </th>
                    </tr>
                    <%
                      int i = 0;
                      foreach (var file in Model._Files)
                      { %>
                    <tr id="file-<%=i %>">
                        <td><a href="/Uploadedfiles/<%=Model._Portal.Name.ToUrlFormat() %>/<%=file.Name%>">
                            <%=Html.Encode(file.Name)%></a>
                        </td>
                        <td>
                            <%=Html.Encode(file.Length)%>
                        </td>
                        <td>
                            <%=Html.Encode(file.LastWriteTime)%>
                        </td>
                        <td>
                           <a onclick="DeleteFile('<%=file.Name %>', <%=i %>)" href="javascript:void(0)">Del</a> 
                        </td>
                    </tr>
                    <%i += 1;
                      } %>
                </table>
            </fieldset>
        </div>
        <%} %>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
<script type="text/javascript" >

    function DeleteFile(fileToDelete, rownum) {
        $.post(
            "/backofficeajax/deletefile/0/" + fileToDelete,
            function(data) {
                var objdata = JSON.parse(data);
                if (objdata.error) {
                    alert(objdata.error);
                }
                else {
                    if (objdata.result == "success") {
                        RemoveFileContainer(rownum);
                    }
                    else {
                        alert("There was a problem removing the file.");
                    }
                }
            },
            "json"
            );
    }

    function RemoveFileContainer(rownum) {
        $("#file-" + rownum).fadeOut("normal", function() {
            $(this).remove();
        });
    }


</script>
</asp:Content>
